package com.bwie.bwedu.model;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.bwie.bwedu.bean.response.BaseResponse;
import com.bwie.bwedu.bean.response.MainInfoResponse;
import com.bwie.bwedu.utils.LogUtils;
import com.bwie.bwedu.volley.RequestAPI;

/**
 * Created by zhang on 2016/7/22.
 */
public class WaittingConfirmFragmentModelImpel implements WaittingConfirmFragmentModel {
    @Override
    public void http(String flag, String pn, final Listener listener) {
        LogUtils.d("----------------WaittingConfirmFragmentModelImpel---------------------");
        RequestAPI.getMainInfo(flag, pn, new Response.Listener<MainInfoResponse>() {
                    @Override
                    public void onResponse(MainInfoResponse userResponse) {
                        if (userResponse.ok) {
                            listener.success(userResponse);
                        } else {
                            listener.error(userResponse.msg);
                        }
                    }
                }
                , new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        LogUtils.d("-------------------------------------");
                        listener.error("网络请求失败");
                    }
                });
    }
    public void Invalidhttp(final String id, final InvalidListener invalid) {
        RequestAPI.invalid(id, new Response.Listener<MainInfoResponse>() {
                    @Override
                    public void onResponse(MainInfoResponse userResponse) {
                        if (userResponse.ok) {
                            invalid.invalidsuccess(userResponse);
                        } else {
                            invalid.invaliderror(userResponse.msg);
                        }
                    }
                }
                , new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        invalid.invaliderror("网络请求失败");
                    }
                });
    }

    @Override
    public void valid(String id, final ValidListener listener) {
        RequestAPI.valid(id, new Response.Listener<BaseResponse>() {
                    @Override
                    public void onResponse(BaseResponse baseResponse) {
                       if (baseResponse.ok==true){
                           listener.validsuccess();
                       }else{
                           listener.validerror(baseResponse.msg);
                       }
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        listener.validerror("请检查网路");
                    }
                });
    }
}